<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/layuimini/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">登陆时间</label>
                            <div class="layui-inline" id="test-range">
                              <div class="layui-input-inline">
                                <input type="text" id="test" class="layui-input" placeholder="登陆时间" name="logintime">
                              </div>
                            </div>
                          </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">登陆状态</label>
                            <div class="layui-input-inline">
                                <select name="status">
                                    <option value="">请选择状态</option>
                                    <option value="1">登录成功</option>
                                    <option value="0">登录失败</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除30日前日志 </button>
                <button class="layui-btn layui-btn-sm data-export-btn" lay-event="export"> 导出 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<script src="/static/admin/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate,
            table = layui.table;
            laydate.render({ 
                elem: '#test'
                ,type: 'datetime'
                ,range: true
                ,format: 'yyyy/MM/dd HH:mm:ss' //可任意组合
            });
        table.render({
            elem: '#currentTableId',
            url: "{:url('Log/loginLog')}"+'?_action=loginLog',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'id', title: 'ID', sort: true},
                {field: 'username', title: '用户名'},
                {field: 'password', title: '密码'},
                {field: 'info', title: '说明'},
                {field: 'status', title: '状态',templet: function (d) {
                        if (d.status == 1) {
                            return '<span class="layui-badge layui-bg-blue">登录成功</span>';
                        } else {
                            return '<span class="layui-badge layui-bg-cyan">登录失败</span>';
                        }
                    }},
                {field: 'logintime', title: '登陆时间', minWidth: 170},
                {field: 'loginip', title: '登陆ip', minWidth: 170},
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            // skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: data.field
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'delete') {  // 监听删除操作
                $.ajax({
                    url: "{:url('Log/deleteLoginLog')}",
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                table.reload('currentTableId');
                            });
                    },
                    error: function (xhr, textstatus, thrown) {
                        return layer.msg('Status:' + xhr.status + '，' + xhr.statusText + '，请稍后再试！');
                    }
                });
            }else if (obj.event === 'export') {  // 监听删除操作
                window.location.href = "{:url('Log/logExport')}";
            }
        });

      
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            
        });

    });
</script>

</body>
</html>